﻿using System;
using Microsoft.Extensions.DependencyInjection;

namespace IOC1
{
    class Program
    {
        static void Main(string[] args)
        {
            ICO1();
        }

        static void ICO1()
        {
            #region 使用  Microsoft.Extensions.DependencyInjection 演示1

            ServiceCollection serColl = new ServiceCollection();
            serColl.AddTransient<MyPeople>();


            using (ServiceProvider sp = serColl.BuildServiceProvider()) //服务定位器
            {
                var p = sp.GetService<MyPeople>(); // 要个服务
                p.Name = "tom";
                p.Say();
                var p1 = sp.GetService<MyPeople>();

                //判断Transient 生命周期，是不是一个对象
                Console.WriteLine(object.ReferenceEquals(p,p1));
            }
            Console.ReadKey();
            #endregion
        }
    }
}
